package com.yang.trainingCamp.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yang.trainingCamp.dao.CoachMapper;
import com.yang.trainingCamp.dao.EntryRecordMapper;
import com.yang.trainingCamp.dao.RegionMapper;
import com.yang.trainingCamp.dao.RoleMapper;
import com.yang.trainingCamp.pojo.Coach;
import com.yang.trainingCamp.pojo.EntryRecord;
import com.yang.trainingCamp.pojo.Region;
import com.yang.trainingCamp.pojo.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class CoachService {

    @Autowired
    private CoachMapper coachMapper;

    @Autowired
    private RegionMapper regionMapper;

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private EntryRecordMapper entryRecordMapper;

    public Map<String, Object> EnableDisable(String coachOrRegionId, String coachOrRegion, String enableOrDisable){

        if (coachOrRegion.equals("1")){
            if (enableOrDisable.equals("2")) {
                QueryWrapper<EntryRecord> entryRecordQueryWrapper = new QueryWrapper<>();
                entryRecordQueryWrapper.eq("in_camp", 2);
                entryRecordQueryWrapper.eq("coach_id", coachOrRegionId);
                if (entryRecordMapper.selectCount(entryRecordQueryWrapper) > 0) {
                    Map<String, Object> msg = new HashMap<String, Object>();
                    msg.put("massage", "该教练名下还有在营的营员");
                    msg.put("code", 400);
                    return msg;
                }

                Coach coach = new Coach();
                coach.setId(coachOrRegionId);
                coach.setDisable(2);
                coachMapper.updateById(coach);
            }else {
                Coach coach = new Coach();
                coach.setId(coachOrRegionId);
                coach.setDisable(1);
                coachMapper.updateById(coach);
            }
        }else {
            if (enableOrDisable.equals("2")) {
                QueryWrapper<EntryRecord> entryRecordQueryWrapper = new QueryWrapper<>();
                entryRecordQueryWrapper.eq("in_camp", 2);
                entryRecordQueryWrapper.eq("region_id", coachOrRegionId);
                if (entryRecordMapper.selectCount(entryRecordQueryWrapper) > 0) {
                    Map<String, Object> msg = new HashMap<String, Object>();
                    msg.put("massage", "该区域下还有在营的营员");
                    msg.put("code", 400);
                    return msg;
                }

                Region region = new Region();
                region.setId(coachOrRegionId);
                region.setDisable(2);
                regionMapper.updateById(region);
            }else {
                Region region = new Region();
                region.setId(coachOrRegionId);
                region.setDisable(1);
                regionMapper.updateById(region);
            }
        }

//        Role role1 = new Role();
//        role1.setName("带队老师");
//        roleMapper.insert(role1);
//
//        Role role = new Role();
//        role.setName("教练");
//        roleMapper.insert(role);
//
//        Coach coach = new Coach();
//        coach.setName("白神悟空");
//        coach.setDisable(1);
//        coach.setRoleId(role.getId());
//        coach.setRoleName(role.getName());
//        coachMapper.insert(coach);
//
//        Coach coach1 = new Coach();
//        coach1.setName("深蓝贝吉塔");
//        coach1.setDisable(1);
//        coach1.setRoleId(role.getId());
//        coach.setRoleName(role.getName());
//        coachMapper.insert(coach1);
//
//        Region region = new Region();
//        region.setName("东部联盟");
//        region.setDisable(1);
//        regionMapper.insert(region);
//
//        Region region1 = new Region();
//        region1.setName("西部部联盟");
//        region1.setDisable(1);
//        regionMapper.insert(region1);

        Map<String, Object> msg = new HashMap<String, Object>();
        msg.put("massage", "成功");
        msg.put("code", 200);
        return msg;
    }
}
